package com.hinnotek.warehouse.bean

import com.blankj.utilcode.util.TimeUtils
import com.google.gson.annotations.Expose
import com.hinnotek.warehouse.utils.WAREHOUSE_GOODS_TYPE_1
import com.hinnotek.warehouse.utils.WAREHOUSE_GOODS_TYPE_2
import com.hinnotek.warehouse.utils.WAREHOUSE_GOODS_TYPE_3
import java.io.Serializable
import java.text.SimpleDateFormat
import java.util.*

data class MachineAccountBean(
    val applyId: Int,
    val applyNum: String,
    var applyType: String,
    val applyUser: String,
    val applyUserId: Int,
    val applyUserType: Int,
    val approvalDate: Long?,
    var approvalState: Int,
    val approvalUser: String,
    val approvalUserId: Int,
    var completeState: Int,
    val contractNo: String,
    val createTime: String,
    val createUser: String,
    val deleteFlag: Int,
    val deviceCount: String,
    val goodsType: String,
    val orderNum: String,
    val projectRemarks: String,
    val refusalReasons: String,
    val sendUser: String,
    val sendUserId: String,
    val state: String,
    val updateTime: String,
    val updateUser: String,
    val wareId: Int,
    val wareName: String,
    val warehourseApplyFormDevices: MutableList<WarehourseApplyFormDevice>
) : Serializable {

    //01-入库单；02-出库单；03-借用单；04-报损单；05-预出库
    val applyTypeData: String
        get() {
            return if (applyType == "01") "入库单" else if (applyType == "02") "出库单" else if (goodsType == "03") "借用单" else if (goodsType == "04") "报损单" else if (goodsType == "05") "预出库单" else "其他"
        }

    //'货物类别：01-成品；02-半成品；03-原材料'
    val goodsTypeData: String
        get() {
            return if (goodsType == WAREHOUSE_GOODS_TYPE_1) "成品" else if (goodsType == WAREHOUSE_GOODS_TYPE_2) "半成品" else if (goodsType == WAREHOUSE_GOODS_TYPE_3) "原材料" else "其他"
        }

    //'申请单状态：1-未完成；2-已完成；3-已撤回；默认1',
    val completeStateData: String
        get() {
            return if (completeState == 1) "未完成" else if (completeState == 2) "已完成" else if (completeState == 3) "已撤回" else "未完成"
        }

    //'审批状态：1-已申请；2-已同意；3-已拒绝；4-已撤回；默认1',
    val approvalStateData: String
        get() {
            return if (approvalState == 1) "已申请" else if (completeState == 2) "已同意" else if (completeState == 3) "已拒绝" else if (completeState == 3) "已撤回" else "已申请"
        }

    //申请时间
    val approvalTime: String
        get() {
            if (approvalDate == null) return ""
            return SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.getDefault()
            ).format(Date(approvalDate))
        }

}

data class MachineListBean(
    val applyDeviceId: Int,
    val applyId: Int,
    var approvalState: Int = 0,
    val deviceAccounts: String,
    var goodsType: String,
    val deviceCount: String?,
    val scanCount: String?,
    val deviceHalfAccounts: String,
    val materielModel: String,
    val materielName: String,
    val materielNum: String
) : Serializable {
    //判断扫描数量是否完成
    val scanOver: Boolean
        get() {
            //审核通过后再判断数量显示按钮
            return when {
                goodsType != WAREHOUSE_GOODS_TYPE_1 -> {
                    return false
                }
                approvalState == 2 -> {
                    scanCount ?: "0" != deviceCount ?: "0"
                }
                else -> {
                    false
                }
            }
        }
}

data class MachineDetailBean(
    val createUserId: Int,
    val deviceId: Int,
    val deviceModel: String,
    val deviceName: String,
    val deviceType: String,
    val deviceTypeName: String,
    val inputOutput: String,
    val instructionsUrl: String,
    val materielNum: String,
    val personName: String,
    val productCertificateUrl: String,
    val productMoney: String,
    val warehouseDeviceNum: String,
    val productNum: String,
    val productNumUrl: String,
    val productTime: String,
    val productTimeEnd: String,
    val productTimeStart: String,
    val frmlossState: String,
    val borrowState: String,
    val testReportUrl: String,
    val updateUser: String,
    val wareId: String,
    val outputTime: Long?,
    val inputTime: Long?,
    val frmlossTime: Long?,
    val borrowTime: Long?,
    var applyType: String
) {
    //01-入库单；02-出库单；03-借用单；04-报损单；05-预出库
    var applyTypeTime = ""
        get() {
            return when (applyType) {
                "01" -> "入库时间：" + TimeUtils.date2String(Date(inputTime ?: 0), "yyyy/MM/dd HH:mm")
                "02" -> "出库时间：" + TimeUtils.date2String(Date(outputTime ?: 0), "yyyy/MM/dd HH:mm")
                "03" -> "借用时间：" + TimeUtils.date2String(Date(borrowTime ?: 0), "yyyy/MM/dd HH:mm")
                "04" -> "报损时间：" + TimeUtils.date2String(Date(frmlossTime ?: 0), "yyyy/MM/dd HH:mm")
                "05" -> ""
                else -> ""
            }
        }
}

data class WarehourseApplyFormDevice(
    val applyDeviceId: Int,
    val applyId: Int,
    val createTime: Any,
    val createUser: Any,
    val deviceAccounts: MutableList<DeviceAccount>,
    val deviceCount: String,
    val deviceHalfAccounts: Any,
    val materielModel: String,
    val materielName: String,
    val materielNum: String,
    val updateTime: Any,
    val updateUser: Any
)

data class DeviceAccount(
    val createTime: Long,
    val createUser: String,
    val createUserId: Int,
    val deleteFlag: Int,
    val deviceId: Int,
    val deviceModel: String,
    val deviceName: String,
    val deviceType: String,
    val deviceTypeName: String,
    val inputOutput: String,
    val inputTime: Any,
    val instructionsUrl: Any,
    val materielNum: Any,
    val outputTime: Any,
    val personName: Any,
    val productCertificateUrl: Any,
    val productMoney: Any,
    val productNum: String,
    val productNumUrl: String,
    val productTime: Any,
    val productTimeEnd: Any,
    val productTimeStart: Any,
    val frmlossState: String,
    val borrowState: String,
    val startTime: Any,
    val testReportUrl: Any,
    val updateTime: Long,
    val updateUser: Any,
    val wareId: Any
)

data class WarehourseApplyFormDevicesProjects(var warehourseApplyFormDevices: List<WarehourseApplyFormDevices>)

data class WarehourseApplyFormDevices(
    @Expose
    var index: Int,
    var materielNum: String,
    var materielName: String,
    var materielModel: String,
    var deviceCount: String?,
    var createUser: String,
) {
    constructor() : this(-1, "", "", "", "", "")

    constructor(materielName: String, materielNum: String, materielModel: String) : this(
        -1,
        materielNum,
        materielName,
        materielModel,
        "",
        ""
    )
}

data class WarehourseApplyFormDevicesRe(
    val deviceModel: String,
    val deviceName: String,
    val materielNum: String,

    val createTime: Long,
    val updateTime: Long,

    val warehouseDeviceNum: Int  //库存
)




